package com.water.camera.view.temp;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.IncludeTemplateFourBinding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Temp4View extends BaseTemp {

    IncludeTemplateFourBinding binding;

    public Temp4View(@NonNull Context context) {
        super(context);
    }

    public Temp4View(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Temp4View(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        super.init(type);
        binding = IncludeTemplateFourBinding.inflate(LayoutInflater.from(getContext()), this, true);
        binding.recycleviewData.setLayoutManager(new LinearLayoutManager(getContext()));
        update();
    }

    @Override
    public void update() {
        setText(binding.tvTitle, "title_temp4", binding.tvTitle);
        setText(binding.tvTitleSecond, "title2_temp4", binding.tvTitleSecond);
        setText(binding.headReportNameTv, "person_temp4", " ", binding.llRecord);
        setText(binding.headReportTimeTv, "date_temp4", " ", binding.llDate);
        setTime(binding.headReportTimeTv, new SimpleDateFormat("yyyy/MM/dd"));

        setText(binding.workdayBefore, "before_temp4", binding.workdayBefore);
        setText(binding.workdayAfter, "after_temp4", binding.workdayAfter);

        int color = getColor();
        binding.tvTitle.setTextColor(color);
        binding.tvTitleSecond.setTextColor(color);
        binding.viewLine.setBackgroundColor(color);
        binding.workdayBefore.setBackgroundColor(color);
        binding.workdayAfter.setBackgroundColor(color);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title_temp4", "标题"));
        list.add(new EditItem("title2_temp4", "小标题"));
        list.add(new EditItem("person_temp4", "汇报人"));
        list.add(new EditItem("date_temp4", "日期", true));
        list.add(new EditItem("before_temp4", "工作前"));
        list.add(new EditItem("after_temp4", "工作后"));

        ArrayList tmp = super.getEditItems();
        tmp.addAll(0, list);
        tmp.add(new EditItem("custom2", "添加自定义选项"));

        return tmp;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.headReportTimeTv, new SimpleDateFormat("yyyy/MM/dd"));
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    protected String getTimeKey() {
        return "date_temp4";
    }

    @Override
    protected int getDefaultColor() {
        return 0xff027864;
    }

    @Override
    protected RecyclerView getCustomRecyclerView() {
        return binding.recycleviewData;
    }
}
